/**
 * 物流方列表返回数据实体
 */
interface LogisticsListItemResponse {
    /**
     * 标识符
     */
    id: string;
    /**
     * 序号
     */
    index: number;
    /**
     * 名称
     */
    name: string;
    /**
     * 所属地区
     */
    address: string;
    /**
     * 用户数
     */
    userCount: number;
    /**
     * 	最后登录时间
     */
    lastLoginTime: string;
}

/**
 * 物流方详细
 */
interface LogisticsDetailResponse extends BaseResponse {
    /**
     * 单位名称
     */
    name: string;
    /**
     * 所属省份
     */
    province: string;
    /**
     * 所属城市
     */
    city: string;
    /**
     * 所属区
     */
    area: string;
    /**
     * 详细地址
     */
    address: string;
    /**
     * 手机号
     */
    phoneNumber: string;
    /**
     * 管理员账户
     */
    adminName: string;
    /**
     * 是否启用
     */
    isEnabled: boolean;
}
/**
 * 获取自动审核信息
 */
interface getAutoAuditDetailResponse extends BaseResponse {
    /**
     * 是否自动审核费用
     */
    isAutoAuditFee:boolean;
    /**
     * 是否自动审核回单
     */
    isAutoAuditReceipt:boolean;
    /**
     * 运单限额
     */
    carrierOrderQuota:string;
    /**
     * 单笔限额
     */
    feeQuota:string;
}

/**
 * 变更自动审核费用开关返回数据
 */
interface changeIsAutoAuditFeeResponse extends BaseResponse{
    /**
     * 是否自动审核费用
     */
    isAutoAuditFee:boolean;
    /**
     * 是否自动审核回单
     */
    isAutoAuditReceipt:boolean;
    /**
     * 运单限额
     */
    carrierOrderQuota:string;
    /**
     * 单笔限额
     */
    feeQuota:string;
}

/**
 * 物流方服务
 */
interface ILogisticsService {

    /**
     * 获取列表
     * v1.0
     * @param name 单位名称
     * @param province 所属省份编号
     * @param city 所属城市编号
     * @param area 所属区编号
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(name: string, province: string, city: string, area: string, skip: number, count: number): ng.IHttpPromise<ListResponse<LogisticsListItemResponse>>;

    /**
     * 获取详细
     * v1.0
     * @param id 物流方编号
     */
    getDetail(id: string): ng.IHttpPromise<LogisticsDetailResponse>;

    /**
     * 添加物流方
     * v1.0
     * @param name 单位名称
     * @param province 所属省份
     * @param city 所属城市
     * @param area 所属区
     * @param address 详细地址
     * @param adminName 管理员账户
     * @param phoneNumber 手机号
     * @param adminPassword 管理员密码
     * @param reAdminPassword 重复管理员密码
     * @param isEnabled 是否启用
     */
    add(name: string, province: string, city: string, area: string, address: string, adminName: string, phoneNumber: string, adminPassword: string, reAdminPassword: string, isEnabled: boolean): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑物流方
     * v1.0
     * @param id 需要编辑的物流方编号
     * @param name 单位名称
     * @param province 所属省份
     * @param city 所属城市
     * @param area 所属区
     * @param address 详细地址
     * @param adminName 管理员账户
     * @param phoneNumber 手机号
     * @param adminPassword 管理员密码
     * @param reAdminPassword 重复管理员密码
     * @param isEnabled 是否启用
     */
    edit(id: string, name: string, province: string, city: string, area: string, address: string, phoneNumber: string, adminPassword: string, reAdminPassword: string, isEnabled: boolean): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除物流方
     * v1.0
     * @param id 删除的物流方编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 获取自动审核信息
     */
    getAutoAuditDetail():ng.IHttpPromise<getAutoAuditDetailResponse>;

    /**
     * 变更自动审核费用开关
     */
    changeIsAutoAuditFee():ng.IHttpPromise<changeIsAutoAuditFeeResponse>
}


class logisticsService implements ILogisticsService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(name: string, province: string, city: string, area: string, skip: number, count: number): ng.IHttpPromise<ListResponse<LogisticsListItemResponse>> {
        return this.http<ListResponse<LogisticsListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("logistics?name={{name}}&province={{province}}&city={{city}}&area={{area}}&skip={{skip}}&count={{count}}", {
                name: name,
                province: province,
                city: city,
                area: area,
                skip: skip,
                count: count
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<LogisticsDetailResponse> {
        return this.http<LogisticsDetailResponse>({
            method: "GET",
            url: this.route.getUrl("logistics/{{id}}", {
                id: id
            })
        });
    }

    add(name: string, province: string, city: string, area: string, address: string, adminName: string, phoneNumber: string, adminPassword: string, reAdminPassword: string, isEnabled: boolean): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("logistics"),
            data: {
                name: name,
                province: province,
                city: city,
                area: area,
                address: address,
                adminName: adminName,
                phoneNumber: phoneNumber,
                adminPassword: adminPassword,
                reAdminPassword: reAdminPassword,
                isEnabled: isEnabled
            }
        });
    }

    edit(id: string, name: string, province: string, city: string, area: string, address: string, phoneNumber: string, adminPassword: string, reAdminPassword: string, isEnabled: boolean): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("logistics/{{id}}", {
                id: id
            }),
            data: {
                name: name,
                province: province,
                city: city,
                area: area,
                address: address,
                phoneNumber: phoneNumber,
                adminPassword: adminPassword,
                reAdminPassword: reAdminPassword,
                isEnabled: isEnabled
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("logistics/{{id}}", {
                id: id
            })
        });
    }

    getAutoAuditDetail():ng.IHttpPromise<getAutoAuditDetailResponse>{
        return this.http<getAutoAuditDetailResponse>({
            method:"GET",
            url:this.route.getUrl("logistics/GetAutoAuditDetail")
        });
    }

    changeIsAutoAuditFee():ng.IHttpPromise<changeIsAutoAuditFeeResponse>{
        return this.http<changeIsAutoAuditFeeResponse>({
            method:"GET",
            url:this.route.getUrl("logistics/ChangeIsAutoAuditFee")
        });
    }
}


angular.module("logisticsService",[]).service("logisticsService",['$http','routeService',logisticsService]);